
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/

#pragma once

#include "CVector3f.h"

//macro to access directly a specific component
#define RTVEC4X _xyzw[0]
#define RTVEC4Y _xyzw[1]
#define RTVEC4Z _xyzw[2]
#define RTVEC4W _xyzw[3]

//Vector composed of four components, X, Y, Z and W
class RTVector4f
{
public :
	//the four components of the vector
	float _xyzw[4];
	
public:
	//empty constructor, set all values to 0
	RTVector4f();

	//constructor : set the values to the parameter's value
	RTVector4f(float x, float y, float z, float w);

	//destructor
	~RTVector4f();

	//add two vectors and return the result
	RTVector4f operator +(const RTVector4f& v)const;

	//substract two vectors and return the result
	RTVector4f operator -(const RTVector4f& v)const;

	//unary substract operation
	RTVector4f operator -()const;

	//multiply with a float and return the result
	RTVector4f operator *(float a)const;

	//multiply two vectors and return the result
	RTVector4f operator *(const RTVector4f& v)const;

	//divide with a float and return the result
	RTVector4f operator /(float a)const;

	//add the parameter and store the result
	void operator += (const RTVector4f& v);

	//add the parameter and store the result
	void operator += (const CVector3f& v);

	//multiply with the parameter and store the result
	void operator *= (float f);

	//equality test. Return true if the two vectors are equals. Return false if the vectors have different values.
	bool operator == (const RTVector4f& v);

	//Return true if the two vectors are different and false if there are equals
	bool operator != (const RTVector4f& v);

	//calculate a dot product (the fourth parameter is ignored)
	float dot(const RTVector4f& v)const;

	//calculate a cross product (the fourth parameter is ignored)
	RTVector4f cross(const RTVector4f& v)const;

	//calculate the vector's norme
	float norme()const;

	//calculate the vector's square norme
	float norme2()const;

	//normalize the vector
	void normalize();

	//saturate the vector between 0 and 1
	void saturate();

	//set the vector to the distance given as parameter
	void maximize(float max);

	//conversion operator to CVector3f
	operator CVector3f();
};